<template>
	<view class="thrmeItem">
		<navigator :url="'/pages/classlist/classlist?id='+item._id+'&name='+item.name" class="box" v-if="!isMore">
			<image :src="item.picurl" mode="aspectFill" class="pic"></image>
			<view class="mask">{{item.name}}</view>
			<view class="tab">{{compareTimestamp(item.updateTime)}}前更新</view>
		</navigator>

		<!-- 更多 -->
		<navigator url="/pages/classify/classify" open-type="reLaunch" class="box more" v-if="isMore">
			<image src="../../common/image/mmexport1693985552261.jpg" mode="aspectFill" class="pic"></image>
			<view class="mask">
				<uni-icons type="more" size="30" color="#fff"></uni-icons>
				<text class="text">更多</text>
			</view>
		</navigator>
	</view>
</template>

<script setup>
	defineProps({
		isMore: {
			type: Boolean,
			default: false
		},
		item: {
			default () {
				return {
					name: '分类名称',
					picurl: '../../common/image/e86bc6c8e21de8b623a0bd1f1955330.jpg',
					updateTime: Date.now() - 1000 * 60 * 60 * 5
				}
			}
		}
	})

	// 更新时间比较
	var compareTimestamp = (timestamp) => {
		const currentTime = new Date().getTime();
		const targetTime = new Date(timestamp).getTime();
		const timeDiff = currentTime - targetTime;

		const minute = 60 * 1000;
		const hour = 60 * minute;
		const day = 24 * hour;
		const month = 30 * day;

		if (timeDiff <= minute) {
			return '一分钟';
		} else if (timeDiff <= hour) {
			return `${Math.floor(timeDiff / minute)} 分钟`;
		} else if (timeDiff <= day) {
			return `${Math.floor(timeDiff / hour)} 小时`;
		} else if (timeDiff <= month) {
			return `${Math.floor(timeDiff / day)} 天`;
		} else if (timeDiff <= 3 * month) {
			return `${Math.floor(timeDiff / month)} 个月`;
		} else {
			return '很久';
		}
	}
</script>

<style lang="scss" scoped>
	.thrmeItem {
		.box {
			height: 340rpx;
			border-radius: 20rpx;
			overflow: hidden; // 解决子元素溢出无法显示圆角
			position: relative;

			.pic {
				width: 100%;
				height: 100%;
			}

			.mask {
				position: absolute;
				bottom: 0;
				left: 0;
				background: rgba(0, 0, 0, 0.1);
				backdrop-filter: blur(66rpx); // 磨砂/模糊效果
				color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 100%;
				height: 70rpx;
				font-size: 30rpx;
				font-weight: 600;
			}

			.tab {
				position: absolute;
				left: 0;
				top: 0;
				background: rgba(255, 129, 90, 0.7);
				backdrop-filter: blur(66rpx);
				color: #fff;
				border-radius: 0 0 30rpx 0;
				font-size: 22rpx;
				padding: 6rpx 14rpx;
			}
		}

		.box.more {
			.mask {
				width: 100%;
				height: 100%;
				flex-direction: column;
			}

			.text {
				font-size: 30rpx;
			}
		}
	}
</style>